#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;
const int N = 3e5 + 10, M = 1e5 + 10;

int n;
int h[M], e[N], ne[N], w[N], idx;
int q[M], dist[M];
bool st[M];

void add(int a, int b, int c){
    e[idx] = b;
    ne[idx] = h[a];
    w[idx] = c;
    h[a] = idx++;
}

int spfa(){
    memset(dist, -0x3f, sizeof dist);
    memset(st, 0, sizeof st);
    int hh = 0, tt = 0;
    dist[0] = 0;
    st[0] = true;
    q[tt++] = 0;

    while(hh != tt){
        int t = q[hh++];
        st[t] = false;
        if(hh == M) hh = 0;

        for(int i = h[t]; ~i; i = ne[i]){
            int j = e[i];
            if(dist[j] < dist[t] + w[i]){
                dist[j] = dist[t] + w[i];
                if(!st[j]){
                    st[j] = true;
                    q[tt++] = j;
                    if(tt == M) tt = 0;
                }
            }
        }
    }

    return dist[50001];
}

int main(){
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    memset(h, -1, sizeof h);
    scanf("%d", &n);
    for(int i = 0; i < n; i ++){
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        a ++, b ++;
        add(a - 1, b, c);
    }

    for(int i = 1; i <= 50001; i ++){
        add(i - 1, i, 0);
        add(i, i - 1, -1);
    }


    int t = spfa();
    printf("%d\n", t);

    return 0;
}